#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

const int N = 10000010;
ll a[N], b[N], c[N];
int n, m;

void set(int l, int r, int s, int e)
{
    int d = (e - s) / (r - l);
    a[l] += s;
    a[l + 1] += d - s;
    a[r + 1] -= d + e;
    a[r + 2] += e;
}


int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int l, r, s, e;
        scanf("%d%d%d%d", &l, &r, &s, &e);
        set(l, r, s, e);
    }

    ll res = 0;
    ll maxn = 0;
    for (int i = 1; i <= n; i++)
    {
        b[i] = b[i - 1] + a[i];
        c[i] = c[i - 1] + b[i];
        res ^= c[i];
        if (c[i] > maxn)
            maxn = c[i];
    }

    printf("%lld %lld\n", res, maxn);

    return 0;
}
